home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / comm / term / term_source.lha / Extras / Source / gtlayout-source.lha / LT_IMsg.c < prev    next >
C/C++ Source or Header  |  1996-08-22  |  5KB  |  202 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #define MESSAGE_COOKIE 0x19138AFB
  15.  
  16. /****** gtlayout.library/LT_GetIMsg ******************************************
  17. *
  18. *   NAME
  19. *    LT_GetIMsg -- Retrieve the next pending IntuiMessage
  20. *                  from the window associated with a
  21. *                  LayoutHandle.
  22. *
  23. *   SYNOPSIS
  24. *    IntuiMessage = LT_GetIMsg(Handle);
  25. *         D0                     A0
  26. *
  27. *    struct IntuiMessage *LT_GetIMsg(LayoutHandle *);
  28. *
  29. *   FUNCTION
  30. *    This routine will handle most of the input loop for
  31. *    you. Just pass the pointer to the layout handle in,
  32. *    check if the result code is non-null, copy the data
  33. *    you need and reply the message via LT_ReplyIMsg().
  34. *
  35. *    You will still need to wait for new input, as LT_GetIMsg
  36. *    will poll the MsgPort of the window.
  37. *
  38. *    LT_GetIMsg() will try its best to distinguish between
  39. *    different LayoutHandles sharing the same Window->UserPort.
  40. *    If it finds that the window the message was sent to is
  41. *    using a different LayoutHandle, it will switch to using
  42. *    this handle (V13).
  43. *
  44. *   INPUTS
  45. *    Handle - Pointer to LayoutHandle structure
  46. *
  47. *   RESULT
  48. *    IntuiMessage - Pointer to IntuiMessage structure
  49. *
  50. *   NOTES
  51. *    You *must not* make any assumptions about the contents
  52. *    of the IntuiMessage structure except for the following
  53. *    entries:
  54. *
  55. *       Class
  56. *       Code
  57. *       Qualifier
  58. *       IAddress
  59. *
  60. *    When finished, you must dispose the IntuiMessage via
  61. *    LT_ReplyIMsg or memory will be lost which can never
  62. *    be reclaimed.
  63. *
  64. *    DO NOT CALL LT_HandleInput() ON THE DATA YOU RECEIVE
  65. *    FROM LT_GetIMsg() AS LT_GetIMsg() ALREADY DOES ALL THE
  66. *    MAGIC LT_HandleInput() OTHERWISE WOULD NEED TO DO!
  67. *    IF YOU STILL DO CALL LT_HandleInput() ON THE DATA YOU
  68. *    WILL RECEIVE `GHOST' EVENTS.
  69. *
  70. *   SEE ALSO
  71. *    gtlayout.library/LT_ReplyIMsg
  72. *
  73. ******************************************************************************
  74. *
  75. */
  76.  
  77. struct IntuiMessage * LIBENT
  78. LT_GetIMsg(REG(a0) struct LayoutHandle *Handle)
  79. {
  80.     if(Handle)
  81.     {
  82.         struct IntuiMessage *Msg = GT_GetIMsg(Handle->Window->UserPort);
  83.  
  84.         if(Msg)
  85.         {
  86.             struct IntuiMessage *Clone;
  87.  
  88.                 // For multiple handles sharing the same UserPort
  89.  
  90.             if(Msg->IDCMPWindow->UserData && !((ULONG)Msg->IDCMPWindow->UserData & 1))
  91.             {
  92.                 LayoutHandle *Local = (LayoutHandle *)Msg->IDCMPWindow->UserData;
  93.  
  94.                 if(Local->PointBack == Local)
  95.                     Handle = Local;
  96.                 else
  97.                     return(Msg);
  98.             }
  99.             else
  100.                 return(Msg);
  101.  
  102.             if(Msg->Class == IDCMP_SIZEVERIFY && Handle->ResizeView)
  103.             {
  104.                     // They're coming to take me away, HAHA!
  105.  
  106.                 Handle->SizeVerified    = TRUE;
  107.                 Handle->SizeWidth        = Handle->Window->Width;
  108.                 Handle->SizeHeight        = Handle->Window->Height;
  109.  
  110.                 LTP_StripGadgets(Handle,Handle->List);
  111.  
  112.                     // Fake a null event, otherwise the following
  113.                     // IDCMP_NEWSIZE would probably not get through
  114.  
  115.                 if(Clone = (struct IntuiMessage *)AllocMem(sizeof(struct IntuiMessage),MEMF_ANY))
  116.                 {
  117.                     CopyMem(Msg,Clone,sizeof(struct IntuiMessage));
  118.  
  119.                     Clone->Class                        = NULL;
  120.                     Clone->ExecMessage.mn_Node.ln_Name    = (char *)MESSAGE_COOKIE;
  121.                     Clone->ExecMessage.mn_Node.ln_Pri     = -114;
  122.                     Clone->ExecMessage.mn_ReplyPort        = (struct MsgPort *)Clone;
  123.                     Clone->SpecialLink                    = (struct IntuiMessage *)Clone;
  124.  
  125.                     GT_ReplyIMsg(Msg);
  126.                 }
  127.             }
  128.             else
  129.             {
  130.                 if(Clone = (struct IntuiMessage *)AllocMem(sizeof(struct IntuiMessage),MEMF_ANY))
  131.                 {
  132.                     CopyMem(Msg,Clone,sizeof(struct IntuiMessage));
  133.  
  134.                     Clone->ExecMessage.mn_Node.ln_Name    = (char *)MESSAGE_COOKIE;
  135.                     Clone->ExecMessage.mn_Node.ln_Pri     = -114;
  136.                     Clone->ExecMessage.mn_ReplyPort        = (struct MsgPort *)Clone;
  137.                     Clone->SpecialLink                    = (struct IntuiMessage *)Clone;
  138.  
  139.                     GT_ReplyIMsg(Msg);
  140.  
  141.                     LT_HandleInput(Handle,Clone->Qualifier,&Clone->Class,&Clone->Code,(struct Gadget **)&Clone->IAddress);
  142.                 }
  143.             }
  144.  
  145.             if(Clone)
  146.                 return(Clone);
  147.             else
  148.                 GT_ReplyIMsg(Msg);
  149.         }
  150.     }
  151.  
  152.     return(NULL);
  153. }
  154.  
  155.  
  156. /*****************************************************************************/
  157.  
  158.  
  159. /****** gtlayout.library/LT_ReplyIMsg ******************************************
  160. *
  161. *   NAME
  162. *    LT_ReplyIMsg -- Dispose of an IntuiMessage received
  163. *
  164. *   SYNOPSIS
  165. *    LT_ReplyIMsg(IntuiMessage);
  166. *                     A0
  167. *
  168. *    VOID LT_ReplyIMsg(struct IntuiMessage *);
  169. *
  170. *   FUNCTION
  171. *    This routine complements LT_GetIMsg().
  172. *
  173. *   INPUTS
  174. *    IntuiMessage - Pointer to IntuiMessage structure,
  175. *        passing NULL is harmless.
  176. *
  177. *   RESULT
  178. *    none
  179. *
  180. *   NOTES
  181. *    Only pass IntuiMessages you received via LT_GetIMsg,
  182. *    or things will get tough.
  183. *
  184. *   SEE ALSO
  185. *    gtlayout.library/LT_GetIMsg
  186. *
  187. ******************************************************************************
  188. *
  189. */
  190.  
  191. VOID LIBENT
  192. LT_ReplyIMsg(REG(a0) struct IntuiMessage *Msg)
  193. {
  194.     if(Msg)
  195.     {
  196.         if(Msg->SpecialLink == (struct IntuiMessage *)Msg && Msg->ExecMessage.mn_Node.ln_Name == (char *)MESSAGE_COOKIE && Msg->ExecMessage.mn_Node.ln_Pri == -114 && Msg->ExecMessage.mn_ReplyPort == (struct MsgPort *)Msg)
  197.             FreeMem(Msg,sizeof(struct IntuiMessage));
  198.         else
  199.             GT_ReplyIMsg(Msg);
  200.     }
  201. }
  202.